#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std; 

typedef long long ll; 

inline ll read(void) {
    char ch;
    ll num=0; 
	ll sign=1;
	
	// skip blank character and get neigetive sign if it exist. 
    for (ch=getchar(); ch<'0'||ch>'9'; ch=getchar()) {
		if(ch=='-') {
			sign = -1;
		}
	}
	
    while(ch>='0' && ch<='9') {
		num = num*10 + (ch-'0'); 
		ch = getchar();
	}
    return sign*num; 
}


int main()
{
	int i, n; 
	ll sum=0, a, r=-100000; 
	
//	freopen("p1115_1.in", "r", stdin); 
	
	scanf("%d", &n); 
	for (i=0; i<n; i++) {
		a = read(); 
		sum += a; 
		r = max(r, sum); 
		if (sum<0) {
			sum = 0; 
		}
	}
	cout<<r<<endl; 
	return 0; 
}

